home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / progwin.zip / HELLOWIN.ZIP / HELLOWIN.C < prev    next >
C/C++ Source or Header  |  1991-09-03  |  2KB  |  82 lines

  1. /*---------------------------------------------------------
  2.    HELLOWIN.C -- Displays "Hello, Windows!" in client area
  3.                  (c) Charles Petzold, 1990
  4.   ---------------------------------------------------------*/
  5.  
  6. #include <windows.h>
  7.  
  8. long FAR PASCAL WndProc (HWND, WORD, WORD, LONG) ;
  9.  
  10. int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance,
  11.             LPSTR lpszCmdParam, int nCmdShow)
  12.     {
  13.     static char szAppName[] = "HelloWin" ;
  14.     HWND        hwnd ;
  15.     MSG        msg ;
  16.     WNDCLASS    wndclass ;
  17.  
  18.     if (!hPrevInstance)
  19.      {
  20.      wndclass.style        = CS_HREDRAW | CS_VREDRAW ;
  21.      wndclass.lpfnWndProc    = WndProc ;
  22.      wndclass.cbClsExtra    = 0 ;
  23.      wndclass.cbWndExtra    = 0 ;
  24.      wndclass.hInstance    = hInstance ;
  25.      wndclass.hIcon        = LoadIcon (NULL, IDI_APPLICATION) ;
  26.      wndclass.hCursor    = LoadCursor (NULL, IDC_ARROW) ;
  27.      wndclass.hbrBackground    = GetStockObject (WHITE_BRUSH) ;
  28.      wndclass.lpszMenuName    = NULL ;
  29.      wndclass.lpszClassName    = szAppName ;
  30.  
  31.      RegisterClass (&wndclass) ;
  32.      }
  33.  
  34.     hwnd = CreateWindow (szAppName,    // window class name
  35.           "The Hello Program",    // window caption
  36.           WS_OVERLAPPEDWINDOW,    // window style
  37.           CW_USEDEFAULT,    // initial x position
  38.           CW_USEDEFAULT,    // initial y position
  39.           CW_USEDEFAULT,    // initial x size
  40.           CW_USEDEFAULT,    // initial y size
  41.           NULL,            // parent window handle
  42.           NULL,            // window menu handle
  43.           hInstance,        // program instance handle
  44.           NULL) ;        // creation parameters
  45.  
  46.     ShowWindow (hwnd, nCmdShow) ;
  47.     UpdateWindow (hwnd) ;
  48.  
  49.     while (GetMessage (&msg, NULL, 0, 0))
  50.      {
  51.      TranslateMessage (&msg) ;
  52.      DispatchMessage (&msg) ;
  53.      }
  54.     return msg.wParam ;
  55.     }
  56.  
  57. long FAR PASCAL WndProc (HWND hwnd, WORD message, WORD wParam, LONG lParam)
  58.     {
  59.     HDC        hdc ;
  60.     PAINTSTRUCT    ps ;
  61.     RECT    rect ;
  62.  
  63.     switch (message)
  64.      {
  65.      case WM_PAINT :
  66.           hdc = BeginPaint (hwnd, &ps) ;
  67.  
  68.           GetClientRect (hwnd, &rect) ;
  69.  
  70.           DrawText (hdc, "Hello, Windows!", -1, &rect,
  71.             DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;
  72.  
  73.           EndPaint (hwnd, &ps);
  74.           return 0 ;
  75.  
  76.      case WM_DESTROY :
  77.           PostQuitMessage (0) ;
  78.           return 0 ;
  79.      }
  80.     return DefWindowProc (hwnd, message, wParam, lParam) ;
  81.     }
  82.